<!DOCTYPE html>
<html>

<head>
  <title>Quarkus - Using the Redis Client</title>
  <script id="adobe_dtm" src="https://www.redhat.com/dtm.js" type="text/javascript"></script>
  <script src="/assets/javascript/highlight.pack.js" type="text/javascript"></script>
  <META HTTP-EQUIV='Content-Security-Policy' CONTENT="default-src 'none'; script-src 'self' 'unsafe-eval' 'sha256-ANpuoVzuSex6VhqpYgsG25OHWVA1I+F6aGU04LoI+5s=' 'sha256-ipy9P/3rZZW06mTLAR0EnXvxSNcnfSDPLDuh3kzbB1w=' js.bizographics.com https://www.redhat.com assets.adobedtm.com jsonip.com https://ajax.googleapis.com https://www.googletagmanager.com https://www.google-analytics.com https://use.fontawesome.com; style-src 'self' https://fonts.googleapis.com https://use.fontawesome.com; img-src 'self' *; media-src 'self' ; frame-src https://www.googletagmanager.com https://www.youtube.com; frame-ancestors 'none'; base-uri 'none'; object-src 'none'; form-action 'none'; font-src 'self' https://use.fontawesome.com https://fonts.gstatic.com;">
  <META HTTP-EQUIV='X-Frame-Options' CONTENT="DENY">
  <META HTTP-EQUIV='X-XSS-Protection' CONTENT="1; mode=block">
  <META HTTP-EQUIV='X-Content-Type-Options' CONTENT="nosniff">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Quarkus: Supersonic Subatomic Java">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:site" content="@QuarkusIO"> 
  <meta name="twitter:creator" content="@QuarkusIO">
  <meta property="og:url" content="https://quarkus.io/guides/redis" />
  <meta property="og:title" content="Quarkus - Using the Redis Client" />
  <meta property="og:description" content="Quarkus: Supersonic Subatomic Java" />
  <meta property="og:image" content="/assets/images/quarkus_card.png" />
  <link rel="canonical" href="https://quarkus.io/guides/redis">
  <link rel="shortcut icon" type="image/png" href="/favicon.ico" >
  <link rel="stylesheet" href="https://quarkus.io/guides/stylesheet/config.css" />
  <link rel="stylesheet" href="/assets/css/main.css" />
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  <link rel="alternate" type="application/rss+xml"  href="https://quarkus.io/feed.xml" title="Quarkus">
  <script src="https://quarkus.io/assets/javascript/goan.js" type="text/javascript"></script>
  <script src="https://quarkus.io/assets/javascript/hl.js" type="text/javascript"></script>
</head>

<body class="guides">
  <!-- Google Tag Manager (noscript) -->
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NJWS5L"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <!-- End Google Tag Manager (noscript) -->

  <div class="nav-wrapper">
  <div class="grid-wrapper">
    <div class="width-12-12">
      <input type="checkbox" id="checkbox" />
      <nav id="main-nav" class="main-nav">
  <div class="container">
    <div class="logo-wrapper">
      
        <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_600px_reverse.png" class="project-logo" title="Quarkus"></a>
      
    </div>
    <label class="nav-toggle" for="checkbox">
      <i class="fa fa-bars"></i>
    </label>
    <div id="menu" class="menu">
      <span>
        <a href="/get-started/" class="">Get Started</a>
      </span>
      <span>
        <a href="/guides/" class="active">Guides</a>
      </span>
      <span>
        <a href="/community/" class="">Community</a>
      </span>
      <span>
        <a href="/support/" class="">Support</a>
      </span>
      <span>
        <a href="/blog/" class="">Blog</a>
      </span>
      <span>
        <a href="https://code.quarkus.io" class="button-cta secondary white">Start Coding</a>
      </span>
    </div>
  </div>
      </nav>
    </div>
  </div>
</div>

  <div class="content">
    <div class="guide">
  <div class="width-12-12">
    <h1 class="text-caps">Quarkus - Using the Redis Client</h1>
    <div class="hide-mobile toc"><ul class="sectlevel1">
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#architecture">Architecture</a></li>
<li><a href="#solution">Solution</a></li>
<li><a href="#creating-the-maven-project">Creating the Maven Project</a></li>
<li><a href="#starting-the-redis-server">Starting the Redis server</a></li>
<li><a href="#configuring-redis-properties">Configuring Redis properties</a></li>
<li><a href="#creating-the-increment-pojo">Creating the Increment POJO</a></li>
<li><a href="#creating-the-increment-service">Creating the Increment Service</a></li>
<li><a href="#creating-the-increment-resource">Creating the Increment Resource</a></li>
<li><a href="#modifying-the-test-class">Modifying the test class</a></li>
<li><a href="#get-it-running">Get it running</a></li>
<li><a href="#interacting-with-the-application">Interacting with the application</a>
<ul class="sectlevel2">
<li><a href="#creating-a-new-increment">Creating a new increment</a></li>
<li><a href="#see-current-increments-keys">See current increments keys</a></li>
<li><a href="#retrieve-a-new-increment">Retrieve a new increment</a></li>
<li><a href="#increment-a-value-given-its-key">Increment a value given its key</a></li>
<li><a href="#deleting-a-key">Deleting a key</a></li>
</ul>
</li>
<li><a href="#packaging-and-running-in-jvm-mode">Packaging and running in JVM mode</a></li>
<li><a href="#running-native">Running Native</a></li>
<li><a href="#connection-health-check">Connection Health Check</a></li>
<li><a href="#configuration-reference">Configuration Reference</a></li>
</ul></div>
    <div>
      <div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>This guide demonstrates how your Quarkus application can connect to a Redis server using the Redis Client extension.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>This technology is considered preview.</p>
</div>
<div class="paragraph">
<p>In <em>preview</em>, backward compatibility and presence in the ecosystem is not guaranteed.
Specific improvements might require to change configuration or APIs and plans to become <em>stable</em> are under way.
Feedback is welcome on our <a href="https://groups.google.com/d/forum/quarkus-dev">mailing list</a> or as issues in our <a href="https://github.com/quarkusio/quarkus/issues">GitHub issue tracker</a>.</p>
</div>
<div class="paragraph">
<p>For a full list of possible extension statuses, check our <a href="https://quarkus.io/faq/#extension-status">FAQ entry</a>.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="prerequisites"><a class="anchor" href="#prerequisites"></a>Prerequisites</h2>
<div class="sectionbody">
<div class="paragraph">
<p>To complete this guide, you need:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>less than 15 minutes</p>
</li>
<li>
<p>an IDE</p>
</li>
<li>
<p>JDK 1.8+ installed with <code>JAVA_HOME</code> configured appropriately</p>
</li>
<li>
<p>Apache Maven 3.5.3+</p>
</li>
<li>
<p>A running Redis server, or Docker Compose to start one</p>
</li>
<li>
<p>GraalVM installed if you want to run in native mode.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="architecture"><a class="anchor" href="#architecture"></a>Architecture</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In this guide, we are going to expose a simple Rest API to increment numbers by using the <a href="https://redis.io/commands/incrby"><code>INCRBY</code></a> command.
Along the way, we&#8217;ll see how to use other Redis commands like <code>GET</code>, <code>SET</code>, <code>DEL</code> and <code>KEYS</code>.</p>
</div>
<div class="paragraph">
<p>We&#8217;ll be using the Quarkus Redis Client extension to connect to our Redis Server. The extension is implemented on top of the <a href="https://vertx.io/docs/vertx-redis-client/java/">Vert.x Redis Client</a>,
providing an asynchronous and non-blocking way to connect to Redis.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="solution"><a class="anchor" href="#solution"></a>Solution</h2>
<div class="sectionbody">
<div class="paragraph">
<p>We recommend that you follow the instructions in the next sections and create the application step by step.
However, you can go right to the completed example.</p>
</div>
<div class="paragraph">
<p>Clone the Git repository: <code>git clone <a href="https://github.com/quarkusio/quarkus-quickstarts.git" class="bare">https://github.com/quarkusio/quarkus-quickstarts.git</a></code>, or download an <a href="https://github.com/quarkusio/quarkus-quickstarts/archive/master.zip">archive</a>.</p>
</div>
<div class="paragraph">
<p>The solution is located in the <code>redis-quickstart</code> <a href="https://github.com/quarkusio/quarkus-quickstarts/tree/master/redis-quickstart">directory</a>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="creating-the-maven-project"><a class="anchor" href="#creating-the-maven-project"></a>Creating the Maven Project</h2>
<div class="sectionbody">
<div class="paragraph">
<p>First, we need a new project. Create a new project with the following command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">mvn io.quarkus:quarkus-maven-plugin:1.7.0.Final:create \
    -DprojectGroupId=org.acme \
    -DprojectArtifactId=redis-quickstart \
    -Dextensions="redis-client, resteasy-jsonb, resteasy-mutiny"
cd redis-quickstart</code></pre>
</div>
</div>
<div class="paragraph">
<p>This command generates a Maven project, importing the Redis extension.</p>
</div>
<div class="paragraph">
<p>If you already have your Quarkus project configured, you can add the <code>redis-client</code> extension
to your project by running the following command in your project base directory:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="bash" class="language-bash hljs">./mvnw quarkus:add-extension -Dextensions="redis-client"</code></pre>
</div>
</div>
<div class="paragraph">
<p>This will add the following to your <code>pom.xml</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs">&lt;dependency&gt;
    &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
    &lt;artifactId&gt;quarkus-redis-client&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="starting-the-redis-server"><a class="anchor" href="#starting-the-redis-server"></a>Starting the Redis server</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Then, we need to start a Redis instance (if you do not have one already) using the following command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="bash" class="language-bash hljs">docker run --ulimit memlock=-1:-1 -it --rm=true --memory-swappiness=0 --name redis_quarkus_test -p 6379:6379 redis:5.0.6</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="configuring-redis-properties"><a class="anchor" href="#configuring-redis-properties"></a>Configuring Redis properties</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Once we have the Redis server running, we need to configure the Redis connection properties.
This is done in the <code>application.properties</code> configuration file. Edit it to the following content:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">quarkus.redis.hosts=localhost:6379 <i class="conum" data-value="1"></i><b>(1)</b></code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Configure Redis hosts to connect to. Here we connect to the Redis server we started in the previous section</p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="creating-the-increment-pojo"><a class="anchor" href="#creating-the-increment-pojo"></a>Creating the Increment POJO</h2>
<div class="sectionbody">
<div class="paragraph">
<p>We are going to model our increments using the <code>Increment</code> POJO.
Create the <code>src/main/java/org/acme/redis/Increment.java</code> file, with the following content:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.redis;

public class Increment {
    public String key; <i class="conum" data-value="1"></i><b>(1)</b>
    public int value; <i class="conum" data-value="2"></i><b>(2)</b>

    public Increment(String key, int value) {
        this.key = key;
        this.value = value;
    }

    public Increment() {
    }
}</code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>The key that will be used as the Redis key</p>
</li>
<li>
<p>The value held by the Redis key</p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="creating-the-increment-service"><a class="anchor" href="#creating-the-increment-service"></a>Creating the Increment Service</h2>
<div class="sectionbody">
<div class="paragraph">
<p>We are going to create an <code>IncrementService</code> class which will play the role of a Redis client.
With this class, we&#8217;ll be able to perform the <code>SET</code>, <code>GET</code> , <code>DELET</code>, <code>KEYS</code> and <code>INCRBY</code> Redis commands.</p>
</div>
<div class="paragraph">
<p>Create the <code>src/main/java/org/acme/redis/IncrementService.java</code> file, with the following content:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.redis;

import io.quarkus.redis.client.RedisClient;
import io.quarkus.redis.client.reactive.ReactiveRedisClient;
import io.smallrye.mutiny.Uni;

import io.vertx.mutiny.redis.client.Response;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
class IncrementService {

    @Inject
    RedisClient redisClient; <i class="conum" data-value="1"></i><b>(1)</b>

    @Inject
    ReactiveRedisClient reactiveRedisClient; <i class="conum" data-value="2"></i><b>(2)</b>

    Uni&lt;Void&gt; del(String key) {
        return reactiveRedisClient.del(Arrays.asList(key))
                .map(response -&gt; null);
    }

    String get(String key) {
        return redisClient.get(key).toString();
    }

    void set(String key, Integer value) {
        redisClient.set(Arrays.asList(key, value.toString()));
    }

    void increment(String key, Integer incrementBy) {
        redisClient.incrby(key, incrementBy.toString());
    }

    Uni&lt;List&lt;String&gt;&gt; keys() {
        return reactiveRedisClient
                .keys("*")
                .map(response -&gt; {
                    List&lt;String&gt; result = new ArrayList&lt;&gt;();
                    for (Response r : response) {
                        result.add(r.toString());
                    }
                    return result;
                });
    }
}</code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Inject the Redis synchronous client</p>
</li>
<li>
<p>Inject the Reactive Redis client</p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="creating-the-increment-resource"><a class="anchor" href="#creating-the-increment-resource"></a>Creating the Increment Resource</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Create the <code>src/main/java/org/acme/redis/IncrementResource.java</code> file, with the following content:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.redis;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.PathParam;
import javax.ws.rs.PUT;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;
import javax.ws.rs.POST;
import javax.ws.rs.DELETE;
import javax.ws.rs.core.MediaType;
import java.util.List;

import io.smallrye.mutiny.Uni;

@Path("/increments")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class IncrementResource {

    @Inject
    IncrementService service;

    @GET
    public Uni&lt;List&lt;String&gt;&gt; keys() {
        return service.keys();
    }

    @POST
    public Increment create(Increment increment) {
        service.set(increment.key, increment.value);
        return increment;
    }

    @GET
    @Path("/{key}")
    public Increment get(@PathParam("key") String key) {
        return new Increment(key, Integer.valueOf(service.get(key)));
    }

    @PUT
    @Path("/{key}")
    public void increment(@PathParam("key") String key, Integer value) {
        service.increment(key, value);
    }

    @DELETE
    @Path("/{key}")
    public Uni&lt;Void&gt; delete(@PathParam("key") String key) {
        return service.del(key);
    }
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="modifying-the-test-class"><a class="anchor" href="#modifying-the-test-class"></a>Modifying the test class</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Edit the <code>src/test/java/org/acme/redis/IncrementResourceTest.java</code> file to the following content:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.redis;

import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

import static io.restassured.RestAssured.given;

import io.restassured.http.ContentType;

@QuarkusTest
public class IncrementResourceTest {

    @Test
    public void testRedisOperations() {
        // verify that we have nothing
        given()
                .accept(ContentType.JSON)
                .when()
                .get("/increments")
                .then()
                .statusCode(200)
                .body("size()", is(0));

        // create a first increment key with an initial value of 0
        given()
                .contentType(ContentType.JSON)
                .accept(ContentType.JSON)
                .body("{\"key\":\"first-key\",\"value\":0}")
                .when()
                .post("/increments")
                .then()
                .statusCode(200)
                .body("key", is("first-key"))
                .body("value", is(0));

        // create a second increment key with an initial value of 10
        given()
                .contentType(ContentType.JSON)
                .accept(ContentType.JSON)
                .body("{\"key\":\"second-key\",\"value\":10}")
                .when()
                .post("/increments")
                .then()
                .statusCode(200)
                .body("key", is("second-key"))
                .body("value", is(10));

        // increment first key by 1
        given()
                .contentType(ContentType.JSON)
                .body("1")
                .when()
                .put("/increments/first-key")
                .then()
                .statusCode(204);

        // verify that key has been incremented
        given()
                .accept(ContentType.JSON)
                .when()
                .get("/increments/first-key")
                .then()
                .statusCode(200)
                .body("key", is("first-key"))
                .body("value", is(1));

        // increment second key by 1000
        given()
                .contentType(ContentType.JSON)
                .body("1000")
                .when()
                .put("/increments/second-key")
                .then()
                .statusCode(204);

        // verify that key has been incremented
        given()
                .accept(ContentType.JSON)
                .when()
                .get("/increments/second-key")
                .then()
                .statusCode(200)
                .body("key", is("second-key"))
                .body("value", is(1010));

        // verify that we have two keys in registered
        given()
                .accept(ContentType.JSON)
                .when()
                .get("/increments")
                .then()
                .statusCode(200)
                .body("size()", is(2));

        // delete first key
        given()
                .accept(ContentType.JSON)
                .when()
                .delete("/increments/first-key")
                .then()
                .statusCode(204);

        // verify that we have one key left after deletion
        given()
                .accept(ContentType.JSON)
                .when()
                .get("/increments")
                .then()
                .statusCode(200)
                .body("size()", is(1));

        // delete second key
        given()
                .accept(ContentType.JSON)
                .when()
                .delete("/increments/second-key")
                .then()
                .statusCode(204);

        // verify that there is no key left
        given()
                .accept(ContentType.JSON)
                .when()
                .get("/increments")
                .then()
                .statusCode(200)
                .body("size()", is(0));
    }
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="get-it-running"><a class="anchor" href="#get-it-running"></a>Get it running</h2>
<div class="sectionbody">
<div class="paragraph">
<p>If you followed the instructions, you should have the Redis server running.
Then, you just need to run the application using:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs">./mvnw quarkus:dev</code></pre>
</div>
</div>
<div class="paragraph">
<p>Open another terminal and run the <code>curl <a href="http://localhost:8080/increments" class="bare">http://localhost:8080/increments</a></code> command.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="interacting-with-the-application"><a class="anchor" href="#interacting-with-the-application"></a>Interacting with the application</h2>
<div class="sectionbody">
<div class="paragraph">
<p>As we have seen above, the API exposes five Rest endpoints.
In this section we are going to see how to initialise an increment, see the list of current increments,
incrementing a value given its key, retrieving the current value of an increment, and finally deleting
a key.</p>
</div>
<div class="sect2">
<h3 id="creating-a-new-increment"><a class="anchor" href="#creating-a-new-increment"></a>Creating a new increment</h3>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs">curl -X POST -H "Content-Type: application/json" -d '{"key":"first","value":10}' http://localhost:8080/increments <i class="conum" data-value="1"></i><b>(1)</b></code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>We create the first increment, with the key <code>first</code> and an initial value of <code>10</code>.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>Running the above command should return the result below:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="json" class="language-json hljs">{
  "key": "first",
  "value": 10
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="see-current-increments-keys"><a class="anchor" href="#see-current-increments-keys"></a>See current increments keys</h3>
<div class="paragraph">
<p>To see the list of current increments keys, run the following command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs">curl http://localhost:8080/increments</code></pre>
</div>
</div>
<div class="paragraph">
<p>The above command should return  <code>["first"]</code> indicating that we have only one increment thus far.</p>
</div>
</div>
<div class="sect2">
<h3 id="retrieve-a-new-increment"><a class="anchor" href="#retrieve-a-new-increment"></a>Retrieve a new increment</h3>
<div class="paragraph">
<p>To retrieve an increment using its key, we will have to run the below command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs">curl http://localhost:8080/increments/first <i class="conum" data-value="1"></i><b>(1)</b></code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Running this command, should return the following result:</p>
</li>
</ol>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="json" class="language-json hljs">{
  "key": "first",
  "value": 10
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="increment-a-value-given-its-key"><a class="anchor" href="#increment-a-value-given-its-key"></a>Increment a value given its key</h3>
<div class="paragraph">
<p>To increment a value, run the following command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs">curl -X PUT -H "Content-Type: application/json" -d '27' http://localhost:8080/increments/first <i class="conum" data-value="1"></i><b>(1)</b></code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Increment the <code>first</code> value by 27.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>Now, running the command <code>curl <a href="http://localhost:8080/increments/first" class="bare">http://localhost:8080/increments/first</a></code> should return the following result:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="json" class="language-json hljs">{
  "key": "first",
  "value": 37 <i class="conum" data-value="1"></i><b>(1)</b>
}</code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>We see that the value of the <code>first</code> key is now <code>37</code> which is exactly the result of <code>10 + 27</code>, quick maths.</p>
</li>
</ol>
</div>
</div>
<div class="sect2">
<h3 id="deleting-a-key"><a class="anchor" href="#deleting-a-key"></a>Deleting a key</h3>
<div class="paragraph">
<p>Use the command below, to delete an increment given its key.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs">curl -X DELETE  http://localhost:8080/increments/first <i class="conum" data-value="1"></i><b>(1)</b></code></pre>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Delete the <code>first</code> increment.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>Now, running the command <code>curl <a href="http://localhost:8080/increments" class="bare">http://localhost:8080/increments</a></code> should return an empty list <code>[]</code></p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="packaging-and-running-in-jvm-mode"><a class="anchor" href="#packaging-and-running-in-jvm-mode"></a>Packaging and running in JVM mode</h2>
<div class="sectionbody">
<div class="paragraph">
<p>You can run the application as a conventional jar file.</p>
</div>
<div class="paragraph">
<p>First, we will need to package it:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs">./mvnw package</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
This command will start a Redis instance to execute the tests. Thus your Redis containers need to be stopped.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Then run it:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs">java -jar ./target/redis-quickstart-1.0-SNAPSHOT-runner.jar</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="running-native"><a class="anchor" href="#running-native"></a>Running Native</h2>
<div class="sectionbody">
<div class="paragraph">
<p>You can also create a native executable from this application without making any
source code changes. A native executable removes the dependency on the JVM:
everything needed to run the application on the target platform is included in
the executable, allowing the application to run with minimal resource overhead.</p>
</div>
<div class="paragraph">
<p>Compiling a native executable takes a bit longer, as GraalVM performs additional
steps to remove unnecessary codepaths. Use the  <code>native</code> profile to compile a
native executable:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs">./mvnw package -Pnative</code></pre>
</div>
</div>
<div class="paragraph">
<p>Once the build is finished, you can run the executable with:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs">./target/redis-quickstart-1.0-SNAPSHOT-runner</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="connection-health-check"><a class="anchor" href="#connection-health-check"></a>Connection Health Check</h2>
<div class="sectionbody">
<div class="paragraph">
<p>If you are using the <code>quarkus-smallrye-health</code> extension, <code>quarkus-vertx-redis</code> will automatically add a readiness health check
to validate the connection to the Redis server.</p>
</div>
<div class="paragraph">
<p>So when you access the <code>/health/ready</code> endpoint of your application you will have information about the connection validation status.</p>
</div>
<div class="paragraph">
<p>This behavior can be disabled by setting the <code>quarkus.redis.health.enabled</code> property to <code>false</code> in your <code>application.properties</code>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="configuration-reference"><a class="anchor" href="#configuration-reference"></a>Configuration Reference</h2>
<div class="sectionbody">
<div class="paragraph configuration-legend">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> Configuration property fixed at build time - All other configuration properties are overridable at runtime</p>
</div>
<table class="tableblock frame-all grid-all stretch configuration-reference searchable">
<colgroup>
<col style="width: 80%;">
<col style="width: 10%;">
<col style="width: 10%;">
</colgroup>
<tbody>
<tr>
<th class="tableblock halign-left valign-top"><p class="tableblock"><a id="quarkus-redis-client_configuration"></a><a href="#quarkus-redis-client_configuration">Configuration property</a></p></th>
<th class="tableblock halign-left valign-middle"><p class="tableblock">Type</p></th>
<th class="tableblock halign-left valign-middle"><p class="tableblock">Default</p></th>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-redis-client_quarkus.redis.health.enabled"></a><code><a href="#quarkus-redis-client_quarkus.redis.health.enabled">quarkus.redis.health.enabled</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Whether or not an health check is published in case the smallrye-health extension is present.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>true</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-redis-client_quarkus.redis.password"></a><code><a href="#quarkus-redis-client_quarkus.redis.password">quarkus.redis.password</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The redis password</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-redis-client_quarkus.redis.hosts"></a><code><a href="#quarkus-redis-client_quarkus.redis.hosts">quarkus.redis.hosts</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The redis hosts</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">list of host:port</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>localhost:6379</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-redis-client_quarkus.redis.database"></a><code><a href="#quarkus-redis-client_quarkus.redis.database">quarkus.redis.database</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The redis database</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">int</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>0</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-redis-client_quarkus.redis.timeout"></a><code><a href="#quarkus-redis-client_quarkus.redis.timeout">quarkus.redis.timeout</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The maximum delay to wait before a blocking command to redis server times out</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><a href="https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html">Duration</a>
  <a href="#duration-note-anchor" title="More information about the Duration format"><span class="icon"><i class="fa fa-question-circle"></i></span></a></p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>10s</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-redis-client_quarkus.redis.ssl"></a><code><a href="#quarkus-redis-client_quarkus.redis.ssl">quarkus.redis.ssl</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Enables or disables the SSL on connect.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>false</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-redis-client_quarkus.redis.client-type"></a><code><a href="#quarkus-redis-client_quarkus.redis.client-type">quarkus.redis.client-type</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The redis client type</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>standalone</code>, <code>sentinel</code>, <code>cluster</code></p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>standalone</code></p></td>
</tr>
</tbody>
</table>
<div id="duration-note-anchor" class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="title">About the Duration format</div>
<div class="paragraph">
<p>The format for durations uses the standard <code>java.time.Duration</code> format.
You can learn more about it in the <a href="https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html#parse-java.lang.CharSequence-">Duration#parse() javadoc</a>.</p>
</div>
<div class="paragraph">
<p>You can also provide duration values starting with a number.
In this case, if the value consists only of a number, the converter treats the value as seconds.
Otherwise, <code>PT</code> is implicitly prepended to the value to obtain a standard <code>java.time.Duration</code> format.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
    </div>
  </div>
</div>

  </div>

  <div class="content project-footer">
  <div class="footer-section">
    <div class="logo-wrapper">
      <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_reverse.svg" class="project-logo" title="Quarkus"></a>
    </div>
  </div>
  <div class="grid-wrapper">
    <p class="grid__item width-3-12">Quarkus is open. All dependencies of this project are available under the <a href='https://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache Software License 2.0</a> or compatible license.<br /><br />This website was built with <a href='https://jekyllrb.com/' target='_blank'>Jekyll</a>, is hosted on <a href='https://pages.github.com/' target='_blank'>Github Pages</a> and is completely open source. If you want to make it better, <a href='https://github.com/quarkusio/quarkusio.github.io' target='_blank'>fork the website</a> and show us what you’ve got.</p>

    
      <div class="width-1-12 project-links">
        <span>Navigation</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="/">Home</a></li>
          
            <li><a href="/guides">Guides</a></li>
          
            <li><a href="/community/#contributing">Contribute</a></li>
          
            <li><a href="/faq">FAQ</a></li>
          
            <li><a href="/get-started">Get Started</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Contribute</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://twitter.com/quarkusio">Follow us</a></li>
          
            <li><a href="https://github.com/quarkusio">GitHub</a></li>
          
            <li><a href="/security">Security&nbsp;policy</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Get Help</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://groups.google.com/forum/#!forum/quarkus-dev">Forums</a></li>
          
            <li><a href="https://quarkusio.zulipchat.com">Chatroom</a></li>
          
        </ul>
      </div>
    

    
      <div class="width-3-12 more-links">
        <span>Quarkus is made of community projects</span>
        <ul class="footer-links">
          
            <li><a href="https://vertx.io/" target="_blank">Eclipse Vert.x</a></li>
          
            <li><a href="https://microprofile.io" target="_blank">Eclipse MicroProfile</a></li>
          
            <li><a href="https://hibernate.org" target="_blank">Hibernate</a></li>
          
            <li><a href="https://netty.io" target="_blank">Netty</a></li>
          
            <li><a href="https://resteasy.github.io" target="_blank">RESTEasy</a></li>
          
            <li><a href="https://camel.apache.org" target="_blank">Apache Camel</a></li>
          
            <li><a href="https://code.quarkus.io/" target="_blank">And many more...</a></li>
          
        </ul>
      </div>
    
  </div>
</div>
  <div class="content redhat-footer">
  <div class="grid-wrapper">
    <span class="licence">
      <i class="fab fa-creative-commons"></i><i class="fab fa-creative-commons-by"></i> <a href="https://creativecommons.org/licenses/by/3.0/" target="_blank">CC by 3.0</a> | <a href="https://www.redhat.com/en/about/privacy-policy">Privacy Policy</a>
    </span>
    <span class="redhat">
      Sponsored by
    </span>
    <span class="redhat-logo">
      <a href="https://www.redhat.com/" target="_blank"><img src="/assets/images/redhat_reversed.svg"></a>
    </span>
  </div>
</div>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" integrity="sha384-8gBf6Y4YYq7Jx97PIqmTwLPin4hxIzQw5aDmUg/DDhul9fFpbbLcLh3nTIIDJKhx" crossorigin="anonymous"></script>
  <script type="text/javascript" src="/assets/javascript/mobile-nav.js"></script>
  <script type="text/javascript" src="/assets/javascript/scroll-down.js"></script>
  <script src="/assets/javascript/satellite.js" type="text/javascript"></script>
  <script src="https://quarkus.io/guides/javascript/config.js" type="text/javascript"></script>
  <script src="/assets/javascript/search-filter.js" type="text/javascript"></script>
  <script src="/assets/javascript/back-to-top.js" type="text/javascript"></script>
</body>

</html>
